﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Fms;

namespace VisionCloud.Api.Controllers.Inner
{
    /// <summary>
    /// Fms模块/内部系统/// </summary>
    [SystemModule("Fms模块")]
    [ApiVersion("1.0")]
    [Route("api/inner/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "Fms模块")]
    public class FmsController : ApiBaseController
    {
        /// <summary>
        /// 日志服务
        /// </summary>
        public FmsService FmsService { get; set; }

        /// <summary>
        /// 作者：黄钧航
        /// 授权访问Fms系统
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet]
        public async Task<ApiResult> GetFmsPublicKey()
        {
            //if(formCollection.Files.Count>0)
            //{
            //    var deviceGuid = formCollection["deviceGuid"];
            //    var type = formCollection["type"];
            //    return await TryCatchAsync(MsLogService.UploadLog(deviceGuid, type, formCollection.Files[0]));
            //}
            //return new ApiResult(AjaxCode.Error, "文件内容为空");
            return await TryCatchAsync(FmsService.UserLoginFms()).ConfigureAwait(false);
        }

        /// <summary>
        /// 作者：黄钧航
        /// 授权访问Fms系统
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<ApiResult> UserLoginFms()
        {
            return await TryCatchAsync(FmsService.UserLoginFms()).ConfigureAwait(false);
        }

        /// <summary>
        /// 作者：黄钧航
        /// 授权访问Fms系统
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<ApiResult> RegisterForApp()
        {
            return await TryCatchAsync(FmsService.RegisterForApp()).ConfigureAwait(false);
        }

        /// <summary>
        /// 作者：黄钧航
        /// 授权访问Fms系统
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<ApiResult> BatchUpdateProjectInfo()
        {
            return await TryCatchAsync(FmsService.BatchUpdateProjectInfo()).ConfigureAwait(false);
        }
    }
}